import { ref, computed, nextTick } from 'vue'
import { defineStore } from 'pinia'

export const useUser = defineStore('user', {
    persist: {
        enabled: true, //开启数据持久化
        strategies: [
            {
                key: "user", //给一个要保存的名称
                storage: localStorage, //sessionStorage / localStorage 存储方式
            },
        ],
    },
    state: () => {
        return {
            userinfo: {
                id: 1,
                username: '',
                Users_corver: '',
            },
            isLogin: false
        }
    },
    actions: {
        storageUserInfo(userinfo) {
            this.userinfo.username = userinfo.Users_name
            this.userinfo.Users_corver = userinfo.Users_corver
            this.userinfo.id = userinfo.id,
            localStorage.setItem("isLogin", true)
            localStorage.setItem("userinfo", JSON.stringify(this.userinfo))
        },
        clearuserinfo() {
            this.userinfo.username = ""
            this.userinfo.Users_corver = ""
            this.userinfo.id = ""
            localStorage.setItem("isLogin", false)
        }
    },
    getters: {

    }
})